<?php

namespace app\service;

use app\models\ContainerProductModel;

class ContainerProductService
{

    /**
     *产品加入装箱表
     */
    public static function addContainerProduct($data, $pid)
    {
        $list  = json_decode($data['product_list'], true);
        $model = new ContainerProductModel();
        foreach ($list as $key => $value) {
            $msg                 = [];
            $msg['staff']        = $data['job_number'];
            $msg['purchase_num'] = $data['purchase_num'];
            $msg['name']         = $value['item'];
            $msg['price']        = $value['price'];
            $msg['num']          = $value['num'];
            $msg['pid']          = $pid;
            $msg['create_at']    = time();
            $model->insert($msg);
        }
    }

    /**
     *删除装箱信息
     *@return bool
     */
    public static function delContainerProduct($purchaseNum): bool
    {
        if (!$purchaseNum) {
            return false;
        }
        $model = new ContainerProductModel();
        $re    = $model->delete(['purchase_num' => $purchaseNum]);
        if ($re) {
            return true;
        }
        return false;
    }
}
